package com.itboye.pondteam.pondteam;

import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;

import com.itboye.pondteam.R;
import com.itboye.pondteam.base.BaseActivity;
import com.itboye.pondteam.popwindow.CustomTimePickerDialog;

import static com.itboye.pondteam.volley.TimesUtils.getWeeksBinary;

public class ActivityChaZuoADetail extends BaseActivity {

    ImageView img_back;
    TextView txt_title, txt_chazuoAopentime, txt_chazuoAclosetime, txt_zhouqi;
    ImageView chazuoA_kaiguan, chazuoA_dingshi;
    RelativeLayout re_zhouqi, re_opentime, re_closetime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cha_zuo_adetail);
        txt_title.setText(getIntent().getStringExtra("title"));
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.img_back) {
            finish();
        }
        if (i == R.id.txt_chazuoAclosetime || i == R.id.re_closetime) {
            setTimerPicker(txt_chazuoAopentime);
        }
        if (i == R.id.txt_chazuoAopentime || i == R.id.re_opentime) {
            setTimerPicker(txt_chazuoAopentime);
        }
        if (i == R.id.txt_zhouqi || i == R.id.re_zhouqi) {
            setTimerPicker(txt_zhouqi);
        }
    }

    public void setTimerPicker(final TextView txtView) {
        int i = txtView.getId();
        String[] times = txtView.getText().toString().split(":");
        if (i == R.id.txt_chazuoAclosetime) {
            Dialog mPicker = new CustomTimePickerDialog(ActivityChaZuoADetail.this, new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    String str = (hourOfDay < 10 ? "0" + hourOfDay : hourOfDay) + ":" + minute;
                    txtView.setText(str);
                }
            }, Integer.parseInt(times[0]), Integer.parseInt(times[1]), true, getString(R.string.chazuoA_closetime));
            mPicker.show();
        } else if (i == R.id.txt_chazuoAopentime) {
            Dialog mPicker = new CustomTimePickerDialog(ActivityChaZuoADetail.this, new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    String str = (hourOfDay < 10 ? "0" + hourOfDay : hourOfDay) + ":" + minute;
                    txtView.setText(str);
                }
            }, Integer.parseInt(times[0]), Integer.parseInt(times[1]), true,  getString(R.string.chazuoA_opentime));
            mPicker.show();
        } else if (i == R.id.txt_zhouqi) {
            Intent intent = new Intent(this, WenDuPeriodActivity.class);
            intent.putExtra("zhouqi", txt_zhouqi.getText().toString());
            startActivityForResult(intent, 101);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 101 && resultCode == 102) {
            int weekNum = data.getIntExtra("weekBinary", 0);
            String ar=getWeeksBinary(weekNum);
            txt_zhouqi.setText(ar+"");
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}
